package com.ruoyi.zxjd.document.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zxjd.document.domain.DocumentFile;
import com.ruoyi.zxjd.document.service.IDocumentFileService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公文附件Controller
 *
 * @author lcc
 * @date 2021-01-28
 */
@Controller
@RequestMapping("/document/file")
public class DocumentFileController extends BaseController {
    private String prefix = "document/file";

    @Autowired
    private IDocumentFileService documentFileService;

    @RequiresPermissions("document:file:view")
    @GetMapping()
    public String file() {
        return prefix + "/file";
    }

    /**
     * 查询公文附件列表
     */
    @RequiresPermissions("document:file:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DocumentFile documentFile) {
        startPage();
        List<DocumentFile> list = documentFileService.selectDocumentFileList(documentFile);
        return getDataTable(list);
    }

    /**
     * 导出公文附件列表
     */
    @RequiresPermissions("document:file:export")
    @Log(title = "公文附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DocumentFile documentFile) {
        List<DocumentFile> list = documentFileService.selectDocumentFileList(documentFile);
        ExcelUtil<DocumentFile> util = new ExcelUtil<DocumentFile>(DocumentFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 新增公文附件
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存公文附件
     */
    @RequiresPermissions("document:file:add")
    @Log(title = "公文附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DocumentFile documentFile) {
        return toAjax(documentFileService.insertDocumentFile(documentFile));
    }

    /**
     * 修改公文附件
     */
    @GetMapping("/edit/{fileId}")
    public String edit(@PathVariable("fileId") Long fileId, ModelMap mmap) {
        DocumentFile documentFile = documentFileService.selectDocumentFileById(fileId);
        mmap.put("documentFile", documentFile);
        return prefix + "/edit";
    }

    /**
     * 修改保存公文附件
     */
    @RequiresPermissions("document:file:edit")
    @Log(title = "公文附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DocumentFile documentFile) {
        return toAjax(documentFileService.updateDocumentFile(documentFile));
    }

    /**
     * 删除公文附件
     */
    @RequiresPermissions("document:file:remove")
    @Log(title = "公文附件", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(documentFileService.deleteDocumentFileByIds(ids));
    }


    /**
     * 查询指定角色的指定公文任务的接收情况
     *
     */
  /*  @RequiresPermissions("document:file:list")
    @GetMapping("/detailList/{arrangeId}/{userId}")
    @ResponseBody
    public TableDataInfo receiveList(@PathVariable("arrangeId")Long arrangeId, @PathVariable("userId") Long userId , ModelMap mmap)
    {
        List<DocumentFile> list = documentFileService.selectDocumentFileListByArrangeIdAndUserId(arrangeId, userId);
//        mmap.put("documentFile", list);
        return getDataTable(list);
    }*/

    /**
     * 查询指定角色的指定公文任务的接收情况
     */
    @RequiresPermissions("document:progress:detail")
    @GetMapping("/detail/{arrangeId}/{userId}")
    public String detail(@PathVariable("arrangeId") Long arrangeId, @PathVariable("userId") Long userId, ModelMap mmap) {
        List<DocumentFile> list = documentFileService.selectDocumentFileListByArrangeIdAndUserId(arrangeId, userId);
        mmap.put("documentFile", list);
//        return prefix + "/detail";
        return "document/progress/detail";
    }
}
